import random
from datetime import datetime


def caseGetPrimaryKeyData():
    # 获取当前时间
    now = datetime.now()

    # 格式化当前时间
    formatted_now = now.strftime("%Y%m%d%H%M%S%f")
    random_integer = "{:05d}".format(random.randint(1, 10000))
    PRIMARYKEY = str(formatted_now) + random_integer
    return PRIMARYKEY

def caseGetPrimaryKey(model,columnsList):
    """
    获取模型的组件
    :param model: 模型
    :param columnsList:
    :return:
    """
    dataList = []
    for itm in columnsList:
        if itm.primary_key == True:
            dataList.append(getattr(model, itm.name))
    if len(dataList)==0:
        return None,"模型不存在主键字段"
    return dataList,None

def caseSetPrimaryKey(columnsList):
    """
    判断主键字段是否为自增不是自增则自动生成数据

    :param columnsList: 模型字段列表
    :return:
    """
    dataDict = {}
    for itm in columnsList:
        # print(itm.name,itm.primary_key,itm.autoincrement)
        if itm.primary_key == True and itm.autoincrement != True:
            dataDict[itm.name] = caseGetPrimaryKeyData()
    return dataDict,None
